package com.superzqb.asus.superzqbFragment.superzqbNews.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbJobShop.Shop.Bean.CommentBean;
import com.superzqb.asus.superzqbFragment.superzqbNews.Bean.NewsContentBean;
import com.superzqb.asus.superzqbUtil.Url;

import java.util.List;

/**
 * Created by asus on 2017/4/24.
 */

public class NewsContentAdapter extends BaseAdapter {
    private Context context;
    private List<NewsContentBean> items;
    public NewsContentAdapter(Context context, List<NewsContentBean> list){
        this.context=context;
        this.items=list;
    }
    public void setList(List<NewsContentBean> list){
        this.items=list;

    }
    @Override
    public int getCount() {
        return items==null?0:items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.comments_item,parent,false);
            convertView.setTag(new NewsContentAdapter.Holder(convertView));
        }
        NewsContentAdapter.Holder holder= (NewsContentAdapter.Holder )convertView.getTag();
        NewsContentBean item=items.get(position);
        holder.content.setText(item.getContent());
        holder.time.setText(item.getTime());
        holder.user.setText(item.getSuid());
        Picasso.with(context).load(new Url().getImg_url() +item.getImg()).into(holder.img);
        return convertView;
    }
    class Holder{
        private ImageView img;
        private TextView user,content,time;
        public Holder(View view){
            user=(TextView)view.findViewById(R.id.user);
            content=(TextView)view.findViewById(R.id.content);
            time=(TextView)view.findViewById(R.id.time);
            img=(ImageView)view.findViewById(R.id.pic);
        }

    }
}
